package com.shaozi.nc.mq.translation;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.shaozi.data.mq.business.base.MqConsts.UserType;
import com.shaozi.data.mq.business.base.SourceTypeConsts.OA.Crm_Custom;
import com.shaozi.data.mq.business.base.SourceTypeConsts.OA.Task;
import com.shaozi.data.mq.business.bean.MQExchangeData;
import com.shaozi.data.mq.business.bean.MQExchangeRuleBean;
import com.shaozi.data.mq.business.bean.MQPushItem;
import com.shaozi.data.mq.business.bus.MqQuartzSchedule;
import com.shaozi.lib.throwable.SzException;

public class CrmCustomPushTranslation extends BaseOaPushTranslation {
	private Logger logger = Logger.getLogger(CrmCustomPushTranslation.class);
	@Autowired
	private MqQuartzSchedule quartzSchedule;
	public CrmCustomPushTranslation() {

	}
	
	@Override
	protected void onTranslatePush(MQExchangeData data, int[] userTypes) throws SzException {
		MQExchangeRuleBean rule = (MQExchangeRuleBean) data.getRule();
		MQPushItem pushItem = rule.getPush();
		switch (pushItem.getSourceType()) {
		case Crm_Custom.DeleteAlarm:
			try {
				quartzSchedule.removeSchedule(data, Crm_Custom.Alarm);
			} catch (SzException e) {
				logger.error(SzException.getStackMessage(e));
			}
			break;
		default:
			super.onTranslatePush(data, userTypes);
			break;
		}

	}

	@Override
	protected int[] onUserType(MQExchangeData data) {
		MQExchangeRuleBean rule = (MQExchangeRuleBean) data.getRule();
		MQPushItem pushItem = rule.getPush();
		switch (pushItem.getSourceType()) {
		case Crm_Custom.BeAdd_Follow_User:
			int[] users1 = { UserType.User1, UserType.User2, UserType.User3 };
			return users1;
		case Crm_Custom.Comment:
		case Crm_Custom.Reply:
			int[] users = { UserType.User1, UserType.User2 };
			return users;
		case Crm_Custom.AddComment:
			int[] userTypes = { UserType.Creator, UserType.Actor, UserType.Principal };
			return userTypes;
		case Crm_Custom.ReplyComment:
			int[] replyUserTypes = { UserType.Creator, UserType.Actor, UserType.Principal, UserType.Comment };
			return replyUserTypes;
		case Crm_Custom.Created:
			int[] defUserTypes = { UserType.Creator, UserType.Actor, UserType.Principal, UserType.Follow };
			return defUserTypes;
		case Crm_Custom.Principal:
			int[] principalUserTypes = { UserType.Principal, UserType.User1 };
			return principalUserTypes;
		case Crm_Custom.Status:
		case Crm_Custom.Actor:
			int[] defUserTypes_ = { UserType.Creator, UserType.Actor, UserType.Principal, UserType.Follow };
			return defUserTypes_;
		case Crm_Custom.Alarm:
		case Crm_Custom.DeleteAlarm:
			return super.onUserType(data);
		default:
			int[] ret = { UserType.Undefine };
			return ret;
		}
	}
}
